package com.guigu.pd.auth.service.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guigu.pd.auth.entity.PageVo;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.common.utils.PageUtils;
import com.guigu.common.utils.Query;

import com.guigu.pd.auth.dao.CoreStationDao;
import com.guigu.pd.auth.entity.CoreStationEntity;
import com.guigu.pd.auth.service.CoreStationService;


@Service("coreStationService")
public class CoreStationServiceImpl extends ServiceImpl<CoreStationDao, CoreStationEntity> implements CoreStationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<CoreStationEntity> page = this.page(
                new Query<CoreStationEntity>().getPage(params),
                new QueryWrapper<CoreStationEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageVo<CoreStationEntity> queryCoreStationEntity(CoreStationEntity coreStationEntity, int pageno, int pagesize) {
        //组装分页
        IPage<CoreStationEntity> page = new Page<CoreStationEntity>(pageno,pagesize);

        //组装条件
        QueryWrapper<CoreStationEntity> queryWrapper = new QueryWrapper<CoreStationEntity>();

        //根据名字模糊查询
        if(StringUtils.isNotBlank(coreStationEntity.getName())) {
            queryWrapper.like("name", coreStationEntity.getName());
        }

        IPage<CoreStationEntity> pageinfo = this.page(page,queryWrapper);

        PageVo<CoreStationEntity> pageVo =new PageVo<CoreStationEntity>();
        pageVo.setRows(pageinfo.getRecords());
        pageVo.setTotal(pageinfo.getTotal());
        return pageVo;
    }
}